package com.r_z.mapper;
import com.r_z.entity.Repertory;
import com.r_z.entity.StoragesDetails;
import org.apache.ibatis.annotations.*;
import java.util.List;
import java.util.Map;

/**
 * @author 任俊杰
 * @version 1.0
 * @date 2023/5/30
 */
@Mapper
public interface RepertoryMapper {
    /**
     * 查询全部
     * @param page 当前页
     * @param limit 每页显示数
     * @param where 查询的条件
     * @return
     */
    @Select("SELECT p.`productId`,p.`productName`,r.`quantity` FROM repertory r INNER JOIN product p ON r.`productId`=p.`productId`  where 1=1 ${where}  limit #{page},#{limit}")
    List<Repertory> selectRepertory(@Param("page") int page, @Param("limit") int limit, @Param("where") String where);

    /**
     * 查询条数
     * @return 条数
     */
    @Select("select count(*) from repertory r join product p on  p.productId=r.productId where 1=1 ${where}")
    int getTotal(String where);


    /**
     * 库存 增加
     * @param repertory 库存实体
     * @return 返回一个标识 i>=1则成功 反之失败
     */
    @Insert("insert into repertory(productId,productName,quantity) values(#{productId},#{productName},#{quantity})")
    int addRepertory(Repertory repertory);

    /**
     * 库存 修改
     * @param repertory 库存实体
     * @return 返回一个标识 i>=1则成功 反之失败
     */
    @Update("update repertory set quantity=#{quantity} where repertoryId=#{repertoryId}")
    int updateRepertory(Repertory repertory);

    /**
     * 库存 删除
     * @param repertory 库存实体
     * @return 返回一个标识 i>=1则成功 反之失败
     */
    @Delete("delete from repertory where repertoryId=#{repertoryId}")
    int deleteRepertory(@Param("repertory") Repertory repertory);

    /**
     * 查入库商品详情的数量
     * @return 商品数量
     */
    @Select("SELECT SUM(quantity)  as quantity FROM storagesDetails GROUP BY goodId;")
    List<StoragesDetails> getStorageCount();
}
